using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Be.Timvw.Framework.Tests.EventHelper
{
    [TestClass]
    public class WhenRaising
    {
        [TestMethod]
        public void ShouldNotThrowWhenNoEventHandlersAreSubscribed()
        {
            MyClass myClass = new MyClass();
            myClass.Name = "name";
        }

        [TestMethod]
        public void ShouldCallEventHandlerWhenEventIsRaised()
        {
            MyClass myClass = new MyClass();
            string name = "name";

            bool eventRaised = false;
            myClass.NameChanged += delegate(object sender, ItemEventArgs<string> e)
            {
                Assert.AreEqual(myClass, sender);
                Assert.AreEqual(name, e.Item);
                eventRaised = true;
            };

            myClass.Name = name;
            Assert.IsTrue(eventRaised);
        }
    }
}